<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class FileController extends Controller
{


	/*
	 * 文件上传
	 * */
    protected function upload(Request $request){
    	if (!$request->hasFile('file')) {
			return response()->json([
				'code'	=> '10001',
				'msg'	=> "上传文件不存在！",
				'data'	=> ""
				]);
		}
		if (!$request->file('file')->isValid()) {
			return response()->json([
				'code'	=> '10001',
				'msg'	=> "无效的文件！",
				'data'	=> ""
				]);
		}
		$extension = $request->file('file')->extension();
		$suffix = array('jpeg','png','gif');
		if(!in_array($extension, $suffix)){
			return response()->json([
				'code'	=> '10001',
				'msg'	=> "文件类型不匹配！",
				'data'	=> ""
				]);
		}
		$path = $request->file('file')->store('images');
		return response()->json([
			'code'	=> '00000',
			'msg'	=> "ok",
			'data'	=> array(
				'path' => $path
				)
			]);
    }

}
